<?php

namespace app\common\model;

use think\Model;

/**
 * 已使用的优惠券
 * Class Coupon
 * @package app\common\model
 */
class CouponUsed extends Model
{
    protected $table = 'coupon_used';

    /**
     * 获取已使用的优惠券 coupon_id => order_sn
     * @param $oauthId
     * @return array
     */
    public static function getColumn($oauthId)
    {
        return static::where(['oauth_id' => $oauthId])->column('order_sn', 'coupon_id');
    }

    /**
     * 获取一条优惠券使用记录
     * @param $oauthId
     * @param $couponId
     * @return array|\PDOStatement|string|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function getOne($oauthId, $couponId)
    {
        return static::field('id')
            ->where([
                'oauth_id' => $oauthId,
                'coupon_id' => $couponId
            ])->find();
    }
}